1 Imports System.Data.SqlClient
2 Imports System.IO
3
4 Public Class frmHostelFeePayment
5 Sub Calculate()
6 Dim num1, num2 As Double
7 num1 = CDbl(Val(txthostelFee.Text) + Val(txtFine.Text) + Val(txtPreviousDue.Text) - Val(txtDiscount.Text))
8 num1 = Math.Round(num1, 2)
9 txtGrandTotal.Text = num1
10 num2 = Val(txtGrandTotal.Text) - Val(txtTotalPaid.Text)
11 num2 = Math.Round(num2, 2)
12 txtBalance.Text = num2
13 End Sub
14 Private Function GenerateID() As String
15 con = New SqlConnection(cs)
16 Dim value As String = "0000"
17 Try
18 ' Fetch the latest ID from the database
19 con.Open()
20 cmd = New SqlCommand("SELECT TOP 1 (HFP_ID) FROM hostelFeePayment where ClassType='Nursery' and SchoolType='English' ORDER BY HFP_ID DESC", con)
21 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
22 If rdr.HasRows Then
23 rdr.Read()
24 value = rdr.Item("HFP_ID")
25 End If
26 rdr.Close()
27 ' Increase the ID by 1
28 value += 1
29 ' Because incrementing a string with an integer removes 0's
30 ' we need to replace them. If necessary.
31 If value <= 9 Then 'Value is between 0 and 10
32 value = "000" & value
33 ElseIf value <= 99 Then 'Value is between 9 and 100
34 value = "00" & value
35 ElseIf value <= 999 Then 'Value is between 999 and 1000
36 value = "0" & value
37 End If
38 Catch ex As Exception
39 ' If an error occurs, check the connection state and close it if necessary.
40 If con.State = ConnectionState.Open Then
41 con.Close()
42 End If
43 value = "0000"
44 End Try
45 Return value
46 End Function
47 Public Sub auto()
48 Try
49 txtHFPId.Text = GenerateID()
50 Dim a As String = txtAdmissionNo.Text
51 txtFeePaymentID.Text = "EHFN-" + GenerateID() + "-" + a
52 Catch ex As Exception
53 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
54 End Try
55 End Sub
56 Private Function GenerateID1() As String
57 con = New SqlConnection(cs)
58 Dim value As String = "0000"
59 Try
60 ' Fetch the latest ID from the database
61 con.Open()
62 cmd = New SqlCommand("SELECT TOP 1 (HFP_ID) FROM hostelFeePayment where ClassType='Primary' and SchoolType='English' ORDER BY HFP_ID DESC", con)
63 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
64 If rdr.HasRows Then
65 rdr.Read()
66 value = rdr.Item("HFP_ID")
67 End If
68 rdr.Close()
69 ' Increase the ID by 1
70 value += 1
71 ' Because incrementing a string with an integer removes 0's
72 ' we need to replace them. If necessary.
73 If value <= 9 Then 'Value is between 0 and 10
74 value = "000" & value
75 ElseIf value <= 99 Then 'Value is between 9 and 100
76 value = "00" & value
77 ElseIf value <= 999 Then 'Value is between 999 and 1000
78 value = "0" & value
79 End If
80 Catch ex As Exception
81 ' If an error occurs, check the connection state and close it if necessary.
82 If con.State = ConnectionState.Open Then
83 con.Close()
84 End If
85 value = "0000"
86 End Try
87 Return value
88 End Function
89 Sub auto1()
90 Try
91 txtHFPId.Text = GenerateID1()
92 Dim a As String = txtAdmissionNo.Text
93 txtFeePaymentID.Text = "EHFP-" + GenerateID1() + "-" + a
94 Catch ex As Exception
95 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
96 End Try
97 End Sub
98 Private Function GenerateID2() As String
99 con = New SqlConnection(cs)
100 Dim value As String = "0000"
101 Try
102 ' Fetch the latest ID from the database
103 con.Open()
104 cmd = New SqlCommand("SELECT TOP 1 (HFP_ID) FROM hostelFeePayment where ClassType='Secondary' and SchoolType='English' ORDER BY HFP_ID DESC", con)
105 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
106 If rdr.HasRows Then
107 rdr.Read()
108 value = rdr.Item("HFP_ID")
109 End If
110 rdr.Close()
111 ' Increase the ID by 1
112 value += 1
113 ' Because incrementing a string with an integer removes 0's
114 ' we need to replace them. If necessary.
115 If value <= 9 Then 'Value is between 0 and 10
116 value = "000" & value
117 ElseIf value <= 99 Then 'Value is between 9 and 100
118 value = "00" & value
119 ElseIf value <= 999 Then 'Value is between 999 and 1000
120 value = "0" & value
121 End If
122 Catch ex As Exception
123 ' If an error occurs, check the connection state and close it if necessary.
124 If con.State = ConnectionState.Open Then
125 con.Close()
126 End If
127 value = "0000"
128 End Try
129 Return value
130 End Function
131 Sub auto2()
132 Try
133 txtHFPId.Text = GenerateID2()
134 Dim a As String = txtAdmissionNo.Text
135 txtFeePaymentID.Text = "EHFS-" + GenerateID2() + "-" + a
136 Catch ex As Exception
137 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
138 End Try
139 End Sub
140 Private Function GenerateID3() As String
141 con = New SqlConnection(cs)
142 Dim value As String = "0000"
143 Try
144 ' Fetch the latest ID from the database
145 con.Open()
146 cmd = New SqlCommand("SELECT TOP 1 (HFP_ID) FROM hostelFeePayment where ClassType='Higher Secondary' and SchoolType='English' ORDER BY HFP_ID DESC", con)
147 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
148 If rdr.HasRows Then
149 rdr.Read()
150 value = rdr.Item("HFP_ID")
151 End If
152 rdr.Close()
153 ' Increase the ID by 1
154 value += 1
155 ' Because incrementing a string with an integer removes 0's
156 ' we need to replace them. If necessary.
157 If value <= 9 Then 'Value is between 0 and 10
158 value = "000" & value
159 ElseIf value <= 99 Then 'Value is between 9 and 100
160 value = "00" & value
161 ElseIf value <= 999 Then 'Value is between 999 and 1000
162 value = "0" & value
163 End If
164 Catch ex As Exception
165 ' If an error occurs, check the connection state and close it if necessary.
166 If con.State = ConnectionState.Open Then
167 con.Close()
168 End If
169 value = "0000"
170 End Try
171 Return value
172 End Function
173 Sub auto3()
174 Try
175 txtHFPId.Text = GenerateID3()
176 Dim a As String = txtAdmissionNo.Text
177 txtFeePaymentID.Text = "EHFHS-" + GenerateID3() + "-" + a
178 Catch ex As Exception
179 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
180 End Try
181 End Sub
182 Private Function GenerateID4() As String
183 con = New SqlConnection(cs)
184 Dim value As String = "0000"
185 Try
186 ' Fetch the latest ID from the database
187 con.Open()
188 cmd = New SqlCommand("SELECT TOP 1 (HFP_ID) FROM hostelFeePayment where ClassType='Nursery' and SchoolType='Gujarati' ORDER BY HFP_ID DESC", con)
189 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
190 If rdr.HasRows Then
191 rdr.Read()
192 value = rdr.Item("HFP_ID")
193 End If
194 rdr.Close()
195 ' Increase the ID by 1
196 value += 1
197 ' Because incrementing a string with an integer removes 0's
198 ' we need to replace them. If necessary.
199 If value <= 9 Then 'Value is between 0 and 10
200 value = "000" & value
201 ElseIf value <= 99 Then 'Value is between 9 and 100
202 value = "00" & value
203 ElseIf value <= 999 Then 'Value is between 999 and 1000
204 value = "0" & value
205 End If
206 Catch ex As Exception
207 ' If an error occurs, check the connection state and close it if necessary.
208 If con.State = ConnectionState.Open Then
209 con.Close()
210 End If
211 value = "0000"
212 End Try
213 Return value
214 End Function
215 Sub auto4()
216 Try
217 txtHFPId.Text = GenerateID4()
218 Dim a As String = txtAdmissionNo.Text
219 txtFeePaymentID.Text = "GHFN-" + GenerateID4() + "-" + a
220 Catch ex As Exception
221 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
222 End Try
223 End Sub
224 Private Function GenerateID5() As String
225 con = New SqlConnection(cs)
226 Dim value As String = "0000"
227 Try
228 ' Fetch the latest ID from the database
229 con.Open()
230 cmd = New SqlCommand("SELECT TOP 1 (HFP_ID) FROM hostelFeePayment where ClassType='Primary' and SchoolType='Gujarati' ORDER BY HFP_ID DESC", con)
231 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
232 If rdr.HasRows Then
233 rdr.Read()
234 value = rdr.Item("HFP_ID")
235 End If
236 rdr.Close()
237 ' Increase the ID by 1
238 value += 1
239 ' Because incrementing a string with an integer removes 0's
240 ' we need to replace them. If necessary.
241 If value <= 9 Then 'Value is between 0 and 10
242 value = "000" & value
243 ElseIf value <= 99 Then 'Value is between 9 and 100
244 value = "00" & value
245 ElseIf value <= 999 Then 'Value is between 999 and 1000
246 value = "0" & value
247 End If
248 Catch ex As Exception
249 ' If an error occurs, check the connection state and close it if necessary.
250 If con.State = ConnectionState.Open Then
251 con.Close()
252 End If
253 value = "0000"
254 End Try
255 Return value
256 End Function
257 Sub auto5()
258 Try
259 txtHFPId.Text = GenerateID5()
260 Dim a As String = txtAdmissionNo.Text
261 txtFeePaymentID.Text = "GHFP-" + GenerateID5() + "-" + a
262 Catch ex As Exception
263 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
264 End Try
265 End Sub
266 Private Function GenerateID6() As String
267 con = New SqlConnection(cs)
268 Dim value As String = "0000"
269 Try
270 ' Fetch the latest ID from the database
271 con.Open()
272 cmd = New SqlCommand("SELECT TOP 1 (HFP_ID) FROM hostelFeePayment where ClassType='Secondary' and SchoolType='Gujarati' ORDER BY HFP_ID DESC", con)
273 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
274 If rdr.HasRows Then
275 rdr.Read()
276 value = rdr.Item("HFP_ID")
277 End If
278 rdr.Close()
279 ' Increase the ID by 1
280 value += 1
281 ' Because incrementing a string with an integer removes 0's
282 ' we need to replace them. If necessary.
283 If value <= 9 Then 'Value is between 0 and 10
284 value = "000" & value
285 ElseIf value <= 99 Then 'Value is between 9 and 100
286 value = "00" & value
287 ElseIf value <= 999 Then 'Value is between 999 and 1000
288 value = "0" & value
289 End If
290 Catch ex As Exception
291 ' If an error occurs, check the connection state and close it if necessary.
292 If con.State = ConnectionState.Open Then
293 con.Close()
294 End If
295 value = "0000"
296 End Try
297 Return value
298 End Function
299 Sub auto6()
300 Try
301 txtHFPId.Text = GenerateID6()
302 Dim a As String = txtAdmissionNo.Text
303 txtFeePaymentID.Text = "GHFS-" + GenerateID6() + "-" + a
304 Catch ex As Exception
305 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
306 End Try
307 End Sub
308 Private Function GenerateID7() As String
309 con = New SqlConnection(cs)
310 Dim value As String = "0000"
311 Try
312 ' Fetch the latest ID from the database
313 con.Open()
314 cmd = New SqlCommand("SELECT TOP 1 (HFP_ID) FROM hostelFeePayment where ClassType='Higher Secondary' and SchoolType='Gujarati' ORDER BY HFP_ID DESC", con)
315 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
316 If rdr.HasRows Then
317 rdr.Read()
318 value = rdr.Item("HFP_ID")
319 End If
320 rdr.Close()
321 ' Increase the ID by 1
322 value += 1
323 ' Because incrementing a string with an integer removes 0's
324 ' we need to replace them. If necessary.
325 If value <= 9 Then 'Value is between 0 and 10
326 value = "000" & value
327 ElseIf value <= 99 Then 'Value is between 9 and 100
328 value = "00" & value
329 ElseIf value <= 999 Then 'Value is between 999 and 1000
330 value = "0" & value
331 End If
332 Catch ex As Exception
333 ' If an error occurs, check the connection state and close it if necessary.
334 If con.State = ConnectionState.Open Then
335 con.Close()
336 End If
337 value = "0000"
338 End Try
339 Return value
340 End Function
341 Sub auto7()
342 Try
343 txtHFPId.Text = GenerateID7()
344 Dim a As String = txtAdmissionNo.Text
345 txtFeePaymentID.Text = "GHFHS-" + GenerateID7() + "-" + a
346 Catch ex As Exception
347 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
348 End Try
349 End Sub
350 Sub Reset()
351 txtAdmissionNo.Text = ""
352 txthostelFee.Text = ""
353 txtPaymentModeDetails.Text = ""
354 txtBalance.Text = ""
355 txtClass.Text = ""
356 txtDiscount.Text = ""
357 txtDiscountPer.Text = ""
358 txtEnrollmentNo.Text = ""
359 txtFine.Text = ""
360 txtGrandTotal.Text = ""
361 txtPreviousDue.Text = ""
362 txtHostelName.Text = ""
363 txtSection.Text = ""
364 txtSession.Text = ""
365 txtStudentName.Text = ""
366 txtTotalPaid.Text = ""
367 txtClassType.Text = ""
368 txtSchoolType.Text = ""
369 cmbPaymentMode.SelectedIndex = -1
370 cmbInstallment.SelectedIndex = -1
371 dtpPaymentDate.Text = Now
372 btnSave.Enabled = True
373 btnUpdate.Enabled = False
374 btnDelete.Enabled = False
375 cmbInstallment.Enabled = True
376 btnPrint.Enabled = False
377 Button2.Enabled = True
378 dtpPaymentDate.Enabled = True
379 End Sub
380 Sub FillData()
381 Try
382 con = New SqlConnection(cs)
383 con.Open()
384 cmd = con.CreateCommand()
385 cmd.CommandText = "SELECT Type FROM ClassType,Class where ClassType.Type=Class.ClassType and Classname=@d1"
386 cmd.Parameters.AddWithValue("@d1", txtClass.Text)
387 rdr = cmd.ExecuteReader()
388 If rdr.Read() Then
389 txtClassType.Text = rdr.GetValue(0).ToString().Trim()
390 End If
391 If (rdr IsNot Nothing) Then
392 rdr.Close()
393 End If
394 If con.State = ConnectionState.Open Then
395 con.Close()
396 End If
397 con = New SqlConnection(cs)
398 con.Open()
399 cmd = con.CreateCommand()
400 cmd.CommandText = "SELECT Type FROM SchoolType,SchoolInfo where SchoolType.Type=SchoolInfo.SchoolType and SchoolName=@d1"
401 cmd.Parameters.AddWithValue("@d1", txtSchoolName.Text)
402 rdr = cmd.ExecuteReader()
403 If rdr.Read() Then
404 txtSchoolType.Text = rdr.GetValue(0).ToString().Trim()
405 End If
406 If (rdr IsNot Nothing) Then
407 rdr.Close()
408 End If
409 If con.State = ConnectionState.Open Then
410 con.Close()
411 End If
412 con = New SqlConnection(cs)
413 con.Open()
414 cmd = con.CreateCommand()
415 cmd.CommandText = "SELECT EnrollmentNo,Session FROM Student where AdmissionNo=@d1"
416 cmd.Parameters.AddWithValue("@d1", txtAdmissionNo.Text)
417 rdr = cmd.ExecuteReader()
418 If rdr.Read() Then
419 txtEnrollmentNo.Text = rdr.GetValue(0).ToString().Trim()
420 txtSession.Text = rdr.GetValue(1).ToString().Trim()
421 End If
422 If (rdr IsNot Nothing) Then
423 rdr.Close()
424 End If
425 If con.State = ConnectionState.Open Then
426 con.Close()
427 End If
428 Catch ex As Exception
429 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
430 End Try
431 End Sub
432 Sub Fill()
433 Try
434 con = New SqlConnection(cs)
435 con.Open()
436 cmd = con.CreateCommand()
437 cmd.CommandText = "SELECT Discount from Discount where AdmissionNo=@d1 and FeeType='Hostel'"
438 cmd.Parameters.AddWithValue("@d1", txtAdmissionNo.Text)
439 rdr = cmd.ExecuteReader()
440 If rdr.Read() Then
441 txtDiscountPer.Text = rdr.GetValue(0)
442 Dim num As Double
443 num = CDbl((Val(txthostelFee.Text) * Val(txtDiscountPer.Text)) / 100)
444 num = Math.Round(num, 2)
445 txtDiscount.Text = num
446 End If
447 If (rdr IsNot Nothing) Then
448 rdr.Close()
449 End If
450 If con.State = ConnectionState.Open Then
451 con.Close()
452 End If
453
454 Calculate()
455 Catch ex As Exception
456 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
457 End Try
458 End Sub
459 Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
460 frmHostelerRecord.lblSet.Text = "Hostel Fee Payment"
461 frmHostelerRecord.Reset()
462 frmHostelerRecord.ShowDialog()
463 End Sub
464
465 Private Sub btnGetFeeList_Click(sender As System.Object, e As System.EventArgs) Handles btnGetFeeList.Click
466 Try
467 If txtAdmissionNo.Text = "" Then
468 MessageBox.Show("Please retrieve hosteler info", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
469 txtAdmissionNo.Focus()
470 Return
471 End If
472 If cmbInstallment.Text = "" Then
473 MessageBox.Show("Please select installment", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
474 cmbInstallment.Focus()
475 Return
476 End If
477 con = New SqlConnection(cs)
478 con.Open()
479 cmd = con.CreateCommand()
480 cmd.CommandText = "SELECT Charges from Installment_Hostel,HostelInfo,SchoolInfo,Class where Installment_Hostel.HostelID=HostelInfo.HI_ID and Installment_Hostel.Class=Class.Classname and SchoolInfo.S_ID=Installment_Hostel.SchoolID and Installment=@d1 and HostelName=@d2 and SchoolName=@d3 and Installment_Hostel.Class=@d4"
481 cmd.Parameters.AddWithValue("@d1", cmbInstallment.Text)
482 cmd.Parameters.AddWithValue("@d2", txtHostelName.Text)
483 cmd.Parameters.AddWithValue("@d3", txtSchoolName.Text)
484 cmd.Parameters.AddWithValue("@d4", txtClass.Text)
485 rdr = cmd.ExecuteReader()
486 If rdr.Read() Then
487 txthostelFee.Text = rdr.GetValue(0)
488 End If
489 If (rdr IsNot Nothing) Then
490 rdr.Close()
491 End If
492 If con.State = ConnectionState.Open Then
493 con.Close()
494 End If
495 con = New SqlConnection(cs)
496 con.Open()
497 cmd = con.CreateCommand()
498 cmd.CommandText = "SELECT Sum(PaymentDue-PreviousDue) from hostelFeePayment where HostelerID=@d1 group by HostelerID"
499 cmd.Parameters.AddWithValue("@d1", txtHostelerID.Text)
500 rdr = cmd.ExecuteReader()
501 If rdr.Read() Then
502 txtPreviousDue.Text = rdr.GetValue(0)
503 Else
504 txtPreviousDue.Text = 0
505 End If
506 If (rdr IsNot Nothing) Then
507 rdr.Close()
508 End If
509 If con.State = ConnectionState.Open Then
510 con.Close()
511 End If
512 Fill()
513 Catch ex As Exception
514 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
515 End Try
516 End Sub
517
518 Private Sub btnNew_Click(sender As System.Object, e As System.EventArgs) Handles btnNew.Click
519 Reset()
520 Reset()
521 End Sub
522
523 Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
524 If Len(Trim(txtAdmissionNo.Text)) = 0 Then
525 MessageBox.Show("Please retrieve hosteler info", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
526 txtAdmissionNo.Focus()
527 Exit Sub
528 End If
529 If Len(Trim(cmbInstallment.Text)) = 0 Then
530 MessageBox.Show("Please select installment", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
531 cmbInstallment.Focus()
532 Exit Sub
533 End If
534 If Len(Trim(txtFine.Text)) = 0 Then
535 MessageBox.Show("Please enter fine", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
536 txtFine.Focus()
537 Exit Sub
538 End If
539 If Len(Trim(cmbPaymentMode.Text)) = 0 Then
540 MessageBox.Show("Please select Payment Mode", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
541 cmbPaymentMode.Focus()
542 Exit Sub
543 End If
544 If Len(Trim(txtTotalPaid.Text)) = 0 Then
545 MessageBox.Show("Please enter total paid", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
546 txtTotalPaid.Focus()
547 Exit Sub
548 End If
549 If Val(txtBalance.Text) < 0 Then
550 MessageBox.Show("Balance is not possible less than zero", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error)
551 Exit Sub
552 End If
553 Try
554 con = New SqlConnection(cs)
555 con.Open()
556 Dim ct As String = "select Session,HostelerID,Installment from hostelFeePayment where Session=@d1 and HostelerID=@d2 and Installment=@d3"
557 cmd = New SqlCommand(ct)
558 cmd.Connection = con
559 cmd.Parameters.AddWithValue("@d1", txtSession.Text)
560 cmd.Parameters.AddWithValue("@d2", txtHostelerID.Text)
561 cmd.Parameters.AddWithValue("@d3", cmbInstallment.Text)
562 rdr = cmd.ExecuteReader()
563 If rdr.Read Then
564 MessageBox.Show("Already paid", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
565 If Not rdr Is Nothing Then
566 rdr.Close()
567 End If
568 Exit Sub
569 End If
570 If txtClassType.Text = "Nursery" And txtSchoolType.Text = "English" Then
571 auto()
572 End If
573 If txtClassType.Text = "Primary" And txtSchoolType.Text = "English" Then
574 auto1()
575 End If
576 If txtClassType.Text = "Secondary" And txtSchoolType.Text = "English" Then
577 auto2()
578 End If
579 If txtClassType.Text = "Higher Secondary" And txtSchoolType.Text = "English" Then
580 auto3()
581 End If
582 If txtClassType.Text = "Nursery" And txtSchoolType.Text = "Gujarati" Then
583 auto4()
584 End If
585 If txtClassType.Text = "Primary" And txtSchoolType.Text = "Gujarati" Then
586 auto5()
587 End If
588 If txtClassType.Text = "Secondary" And txtSchoolType.Text = "Gujarati" Then
589 auto6()
590 End If
591 If txtClassType.Text = "Higher Secondary" And txtSchoolType.Text = "Gujarati" Then
592 auto7()
593 End If
594 con = New SqlConnection(cs)
595 con.Open()
596 Dim cb As String = "insert into hostelFeePayment(HFP_ID, PaymentID, Hostelerid, Session,installment,TotalFee, DiscountPer, DiscountAmt, PreviousDue, Fine, GrandTotal, TotalPaid, ModeOfPayment, PaymentModeDetails, PaymentDate, PaymentDue, ClassType,SchoolType,Class,Section) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16,@d17,@d18,@d19,@d20)"
597 cmd = New SqlCommand(cb)
598 cmd.Connection = con
599 cmd.Parameters.AddWithValue("@d1", txtHFPId.Text)
600 cmd.Parameters.AddWithValue("@d2", txtFeePaymentID.Text)
601 cmd.Parameters.AddWithValue("@d3", txtHostelerID.Text)
602 cmd.Parameters.AddWithValue("@d4", txtSession.Text)
603 cmd.Parameters.AddWithValue("@d5", cmbInstallment.Text)
604 cmd.Parameters.AddWithValue("@d6", txthostelFee.Text)
605 cmd.Parameters.AddWithValue("@d7", txtDiscountPer.Text)
606 cmd.Parameters.AddWithValue("@d8", txtDiscount.Text)
607 cmd.Parameters.AddWithValue("@d9", txtPreviousDue.Text)
608 cmd.Parameters.AddWithValue("@d10", txtFine.Text)
609 cmd.Parameters.AddWithValue("@d11", txtGrandTotal.Text)
610 cmd.Parameters.AddWithValue("@d12", txtTotalPaid.Text)
611 cmd.Parameters.AddWithValue("@d13", cmbPaymentMode.Text)
612 cmd.Parameters.AddWithValue("@d14", txtPaymentModeDetails.Text)
613 cmd.Parameters.AddWithValue("@d15", dtpPaymentDate.Value)
614 cmd.Parameters.AddWithValue("@d16", txtBalance.Text)
615 cmd.Parameters.AddWithValue("@d17", txtClassType.Text)
616 cmd.Parameters.AddWithValue("@d18", txtSchoolType.Text)
617 cmd.Parameters.AddWithValue("@d19", txtClass.Text)
618 cmd.Parameters.AddWithValue("@d20", txtSection.Text)
619 cmd.ExecuteNonQuery()
620 Dim st As String = "added the new hostel fee payment entry having payment id '" & txtFeePaymentID.Text & "'"
621 LogFunc(lblUser.Text, st)
622 MessageBox.Show("Successfully paid", "Fee", MessageBoxButtons.OK, MessageBoxIcon.Information)
623 btnSave.Enabled = False
624 con.Close()
625 Print()
626 Catch ex As Exception
627 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
628 End Try
629 End Sub
630
631 Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
632 Try
633 If MessageBox.Show("Do you really want to delete the record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = Windows.Forms.DialogResult.Yes Then
634 delete_records()
635 End If
636 Catch ex As Exception
637 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
638 End Try
639 End Sub
640 Private Sub delete_records()
641 Try
642 Dim RowsAffected As Integer = 0
643 con = New SqlConnection(cs)
644 con.Open()
645 Dim cq As String = "delete from hostelFeePayment where ID= " & txtID.Text & ""
646 cmd = New SqlCommand(cq)
647 cmd.Connection = con
648 RowsAffected = cmd.ExecuteNonQuery()
649 If RowsAffected > 0 Then
650 Dim st As String = "deleted the hostel fee payment entry having payment id '" & txtFeePaymentID.Text & "'"
651 LogFunc(lblUser.Text, st)
652 MessageBox.Show("Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
653 Reset()
654 Reset()
655 Else
656 MessageBox.Show("No record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information)
657 Reset()
658 Reset()
659 End If
660 con.Close()
661 Catch ex As Exception
662 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
663 End Try
664 End Sub
665
666 Private Sub btnUpdate_Click(sender As System.Object, e As System.EventArgs) Handles btnUpdate.Click
667 If Len(Trim(txtAdmissionNo.Text)) = 0 Then
668 MessageBox.Show("Please retrieve hosteler info", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
669 txtAdmissionNo.Focus()
670 Exit Sub
671 End If
672 If Len(Trim(cmbInstallment.Text)) = 0 Then
673 MessageBox.Show("Please select installment", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
674 cmbInstallment.Focus()
675 Exit Sub
676 End If
677 If Len(Trim(txtFine.Text)) = 0 Then
678 MessageBox.Show("Please enter fine", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
679 txtFine.Focus()
680 Exit Sub
681 End If
682 If Len(Trim(cmbPaymentMode.Text)) = 0 Then
683 MessageBox.Show("Please select Payment Mode", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
684 cmbPaymentMode.Focus()
685 Exit Sub
686 End If
687 If Len(Trim(txtTotalPaid.Text)) = 0 Then
688 MessageBox.Show("Please enter total paid", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
689 txtTotalPaid.Focus()
690 Exit Sub
691 End If
692 If Val(txtBalance.Text) < 0 Then
693 MessageBox.Show("Balance is not possible less than zero", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error)
694 Exit Sub
695 End If
696 Try
697 'con = New SqlConnection(cs)
698 'con.Open()
699 'Dim ct As String = "select PaymentDate from hostelFeePayment where AdmissionNo=@d1"
700 'cmd = New SqlCommand(ct)
701 'cmd.Connection = con
702 'cmd.Parameters.AddWithValue("@d1", txtAdmissionNo.Text)
703 'Dim da As New SqlDataAdapter(cmd)
704 'Dim ds As DataSet = New DataSet()
705 'da.Fill(ds)
706 'If ds.Tables(0).Rows.Count > 0 Then
707 'If dtpPaymentDate.Value.Date < ds.Tables(0).Rows(0)("PaymentDate") Then
708 'MessageBox.Show("updating old record is not allowed when student has been already paid fee again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
709 'End If
710 'Exit Sub
711 'End If
712 'con.Close()
713 con = New SqlConnection(cs)
714 con.Open()
715 Dim cb As String = "Update hostelFeePayment set HFP_ID=@d1, PaymentID=@d2, HostelerID=@d3, Session=@d4, Installment=@d5,TotalFee=@d6, DiscountPer=@d7, DiscountAmt=@d8, PreviousDue=@d9, Fine=@d10, GrandTotal=@d11, TotalPaid=@d12, ModeOfPayment=@d13, PaymentModeDetails=@d14, PaymentDue=@d16, ClassType=@d17,SchoolType=@d18,Class=@d19,Section=@d20 where ID= " & txtID.Text & ""
716 cmd = New SqlCommand(cb)
717 cmd.Connection = con
718 cmd.Parameters.AddWithValue("@d1", txtHFPId.Text)
719 cmd.Parameters.AddWithValue("@d2", txtFeePaymentID.Text)
720 cmd.Parameters.AddWithValue("@d3", txtHostelerID.Text)
721 cmd.Parameters.AddWithValue("@d4", txtSession.Text)
722 cmd.Parameters.AddWithValue("@d5", cmbInstallment.Text)
723 cmd.Parameters.AddWithValue("@d6", txthostelFee.Text)
724 cmd.Parameters.AddWithValue("@d7", txtDiscountPer.Text)
725 cmd.Parameters.AddWithValue("@d8", txtDiscount.Text)
726 cmd.Parameters.AddWithValue("@d9", txtPreviousDue.Text)
727 cmd.Parameters.AddWithValue("@d10", txtFine.Text)
728 cmd.Parameters.AddWithValue("@d11", txtGrandTotal.Text)
729 cmd.Parameters.AddWithValue("@d12", txtTotalPaid.Text)
730 cmd.Parameters.AddWithValue("@d13", cmbPaymentMode.Text)
731 cmd.Parameters.AddWithValue("@d14", txtPaymentModeDetails.Text)
732 cmd.Parameters.AddWithValue("@d16", txtBalance.Text)
733 cmd.Parameters.AddWithValue("@d17", txtClassType.Text)
734 cmd.Parameters.AddWithValue("@d18", txtSchoolType.Text)
735 cmd.Parameters.AddWithValue("@d19", txtClass.Text)
736 cmd.Parameters.AddWithValue("@d20", txtSection.Text)
737 cmd.ExecuteNonQuery()
738 con.Close()
739 Dim st As String = "updated the hostel fee payment entry having payment id '" & txtFeePaymentID.Text & "'"
740 LogFunc(lblUser.Text, st)
741 MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
742 btnUpdate.Enabled = False
743 con.Close()
744 Catch ex As Exception
745 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
746 End Try
747 End Sub
748
749 Private Sub txtFine_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtFine.KeyPress
750 Dim keyChar = e.KeyChar
751
752 If Char.IsControl(keyChar) Then
753 'Allow all control characters.
754 ElseIf Char.IsDigit(keyChar) OrElse keyChar = "."c Then
755 Dim text = Me.txtFine.Text
756 Dim selectionStart = Me.txtFine.SelectionStart
757 Dim selectionLength = Me.txtFine.SelectionLength
758
759 text = text.Substring(0, selectionStart) & keyChar & text.Substring(selectionStart + selectionLength)
760
761 If Integer.TryParse(text, New Integer) AndAlso text.Length > 16 Then
762 'Reject an integer that is longer than 16 digits.
763 e.Handled = True
764 ElseIf Double.TryParse(text, New Double) AndAlso text.IndexOf("."c) < text.Length - 3 Then
765 'Reject a real number with two many decimal places.
766 e.Handled = False
767 End If
768 Else
769 'Reject all other characters.
770 e.Handled = True
771 End If
772 End Sub
773
774 Private Sub txtTotalPaid_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtTotalPaid.KeyPress
775 Dim keyChar = e.KeyChar
776
777 If Char.IsControl(keyChar) Then
778 'Allow all control characters.
779 ElseIf Char.IsDigit(keyChar) OrElse keyChar = "."c Then
780 Dim text = Me.txtTotalPaid.Text
781 Dim selectionStart = Me.txtTotalPaid.SelectionStart
782 Dim selectionLength = Me.txtTotalPaid.SelectionLength
783
784 text = text.Substring(0, selectionStart) & keyChar & text.Substring(selectionStart + selectionLength)
785
786 If Integer.TryParse(text, New Integer) AndAlso text.Length > 16 Then
787 'Reject an integer that is longer than 16 digits.
788 e.Handled = True
789 ElseIf Double.TryParse(text, New Double) AndAlso text.IndexOf("."c) < text.Length - 3 Then
790 'Reject a real number with two many decimal places.
791 e.Handled = False
792 End If
793 Else
794 'Reject all other characters.
795 e.Handled = True
796 End If
797 End Sub
798
799 Private Sub txtTotalPaid_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles txtTotalPaid.Validating
800 If Val(txtTotalPaid.Text) > Val(txtGrandTotal.Text) Then
801 MessageBox.Show("Total Pay can not be more than grand total", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
802 txtTotalPaid.Text = ""
803 txtTotalPaid.Focus()
804 Exit Sub
805 End If
806 End Sub
807
808 Private Sub txtFine_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtFine.TextChanged
809 Fill()
810 End Sub
811
812 Private Sub txtTotalPaid_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtTotalPaid.TextChanged
813 Fill()
814 End Sub
815
816 Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
817 Me.Close()
818 End Sub
819
820 Private Sub btnGetData_Click(sender As System.Object, e As System.EventArgs) Handles btnGetData.Click
821 frmHostelFeePaymentRecord.lblSet.Text = "Hostel Fee Payment"
822 frmHostelFeePaymentRecord.Reset()
823 frmHostelFeePaymentRecord.ShowDialog()
824 End Sub
825 Sub fillInstallment()
826 Try
827 con = New SqlConnection(cs)
828 con.Open()
829 Dim ct As String = "SELECT distinct RTRIM(Installment) FROM Installment_Hostel,HostelInfo where Installment_Hostel.HostelID=HostelInfo.HI_ID and HostelName=@d1"
830 cmd = New SqlCommand(ct)
831 cmd.Parameters.AddWithValue("@d1", txtHostelName.Text)
832 cmd.Connection = con
833 rdr = cmd.ExecuteReader()
834 cmbInstallment.Items.Clear()
835 While rdr.Read
836 cmbInstallment.Items.Add(rdr(0))
837 End While
838 con.Close()
839 Catch ex As Exception
840 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
841 End Try
842 End Sub
843
844 Sub Print()
845 Try
846 Cursor = Cursors.WaitCursor
847 Timer1.Enabled = True
848 Dim rpt As New rptHostelFeeReceipt 'The report you created.
849 Dim myConnection As SqlConnection
850 Dim MyCommand As New SqlCommand()
851 Dim myDA As New SqlDataAdapter()
852 Dim myDS As New DataSet 'The DataSet you created.
853 myConnection = New SqlConnection(cs)
854 MyCommand.Connection = myConnection
855 MyCommand.CommandText = "SELECT SchoolInfo.S_Id, SchoolInfo.SchoolName, SchoolInfo.Address, SchoolInfo.ContactNo, SchoolInfo.AltContactNo, SchoolInfo.FaxNo, SchoolInfo.Email, SchoolInfo.Website, SchoolInfo.Logo, SchoolInfo.RegistrationNo,SchoolInfo.DiseNo, SchoolInfo.IndexNo, SchoolInfo.EstablishedYear, Student.AdmissionNo, Student.EnrollmentNo, Student.GRNo, Student.UID, Student.StudentName,Student.FatherName, Student.MotherName, Student.FatherCN, Student.PermanentAddress, Student.TemporaryAddress, Student.EmailID, Student.DOB, Student.Gender,Student.AdmissionDate, Student.Session, Student.Caste, Student.Religion, Student.SectionID, Student.Photo, Student.Nationality, Student.SchoolID, Student.LastSchoolAttended, Student.Result,Student.PassPercentage, Hosteler.H_Id, Hosteler.HostelID, Hosteler.JoiningDate, HostelFeePayment.Id, HostelFeePayment.HFP_Id,HostelFeePayment.PaymentID, HostelFeePayment.HostelerID, HostelFeePayment.Installment, HostelFeePayment.TotalFee, HostelFeePayment.DiscountPer,HostelFeePayment.DiscountAmt, HostelFeePayment.PreviousDue, HostelFeePayment.Fine, HostelFeePayment.GrandTotal, HostelFeePayment.TotalPaid, HostelFeePayment.ModeOfPayment,HostelFeePayment.PaymentModeDetails, HostelFeePayment.Paymentdate, HostelFeePayment.PaymentDue, HostelFeePayment.ClassType, HostelFeePayment.SchoolType, HostelFeePayment.Class , HostelFeePayment.Section, HostelInfo.HI_Id, HostelInfo.Hostelname, HostelInfo.ManagedBy,HostelInfo.Person_ContactNo FROM SchoolInfo INNER JOIN Student ON SchoolInfo.S_Id = Student.SchoolID INNER JOIN Hosteler ON Student.AdmissionNo = Hosteler.AdmissionNo INNER JOIN HostelFeePayment ON Hosteler.H_Id = HostelFeePayment.HostelerID INNER JOIN HostelInfo ON Hosteler.HostelID = HostelInfo.HI_Id where PaymentID='" & txtFeePaymentID.Text & "'"
856 MyCommand.CommandType = CommandType.Text
857 myDA.SelectCommand = MyCommand
858 myDA.Fill(myDS, "Student")
859 myDA.Fill(myDS, "Hosteler")
860 myDA.Fill(myDS, "SchoolInfo")
861 myDA.Fill(myDS, "HostelFeePayment")
862 myDA.Fill(myDS, "HostelInfo")
863 rpt.SetDataSource(myDS)
864 frmReport.CrystalReportViewer1.ReportSource = rpt
865 frmReport.ShowDialog()
866 Catch ex As Exception
867 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
868 End Try
869 End Sub
870 Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
871 Print()
872 End Sub
873
874 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
875 Cursor = Cursors.Default
876 Timer1.Enabled = False
877 End Sub
878
879 End Class